package zj;

public class test {

    /**
     * java的值传递与对象的引用在实际使用过程中的区别
     * 
     * @param args
     */
    public static void main(String[] args) {

	// 内置对象
	String str = "hello";
	testString(str);
	System.out.println(str);

	// 引用对象
	StringBuffer sbf = new StringBuffer("hello");
	testStringbuffer(sbf);
	System.out.println(sbf);

	// 栈内引用对象
	String[] sra = new String[] { "1", "2" };
	testStringArry(sra);
	System.out.println(sra[1]);

	// 自定对象的引用
	myObject m;
	editObject(m = new myObject());
	System.out.println(m.getStr());

    }


    public static void testString(final String str) {
	str.replace("hello", "do it");
    }

    public static void testStringArry(final String... str) {
	str[1] = "do it";
    }

    public static void testStringbuffer(final StringBuffer str) {
	str.replace(0, str.length(), "do if");
    }

    static void editObject(myObject str) {
	str.setStr("hello");
//	str.setStr(str.getStr().replace("hello", "do it"));
    }

    public static class myObject {
	public myObject() {
	}

	String str;

	public String getStr() {
	    return this.str;
	}

	public void setStr(String str) {
	    this.str = str;
	}

    }
}
